package com.zz.study.sharding.util;

import com.zz.study.sharding.entity.DtFusdataFlinkSimple;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * created by xjx on  2024-01-19 9:47
 */
public class CommonUtil {

    public static Integer getRandomInt(int min, int max){
        Random random = new Random();
        Integer s = random.nextInt(max) % (max - min + 1) + min;
        return s;

    }


    public static Map<String,Object> objToMap(Object obj) throws Exception{
        return Map.class.cast(obj);
    }

    public static List<String> objToList(Object obj) throws Exception{
        List<String> result = new ArrayList<String>();
        if (obj instanceof ArrayList<?>) {
            for (Object o : (List<?>) obj) {
                result.add(String.class.cast(o));
            }
        }
        return result;
    }

    public static List<DtFusdataFlinkSimple> objToListTrackdata(Object obj) throws Exception{
        List<DtFusdataFlinkSimple> result = new ArrayList<DtFusdataFlinkSimple>();
        if (obj instanceof ArrayList<?>) {
            for (Object o : (List<?>) obj) {
                result.add(DtFusdataFlinkSimple.class.cast(o));
            }
        }
        return result;
    }



    public static List<Map<String,Object>> objToMapListTrackdata(Object obj) throws Exception{
        List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
        if (obj instanceof ArrayList<?>) {
            for (Object o : (List<?>) obj) {
                result.add(Map.class.cast(o));
            }
        }
        return result;
    }
}
